﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MoetutuServer.Pixiv.ProcessImg
{
    public partial class Message : Form
    {/// <summary>
    /// 窗体初始化
    /// </summary>
    /// <param name="Tip"></param>
        public Message(String Tip)
        {
            InitializeComponent();
            label1.Text = Tip;
            
        }
        public Message()
        {
            InitializeComponent();
        }
        private static bool returnValue;
        /// <summary>
        /// 返回用户选择的数据
        /// </summary>
        public static bool ReturnValue { get => returnValue; protected set => returnValue = value; }

        
        /// <summary>
        /// 重新获取窗口焦点
        /// </summary>
        private void SetFourcs()
        {
           
            Console.WriteLine("焦点绑定");
            SetF(this.Handle); //设置本窗口获得焦点
        }

    

        /// <summary>
        /// 设置窗体焦点不丢失
        /// </summary>
        /// <returns></returns>
        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetForegroundWindow", CharSet = System.Runtime.InteropServices.CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetF(); //获得本窗体的句柄
        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
        public static extern bool SetF(IntPtr hWnd); //设置此窗体为活动窗体


        private void button1_Click(object sender, EventArgs e)
        {
            Confirm();
        }
        /// <summary>
        /// 确定
        /// </summary>
        private void Confirm()
        {
            ReturnValue = true;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Cancel();
        }
        /// <summary>
        /// 取消
        /// </summary>
        private void Cancel()
        {
            ReturnValue = false;
            this.Close();
        }

        private void Message_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                Cancel();
            }
            else if (e.KeyCode == Keys.Space)
                Confirm();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            SetFourcs();
        }
    }
}
